package com.shfl.Service;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

import com.shfl.Util.POIUtil;
import com.shfl.been.ResultBean;
import com.shfl.model.ResultType;
import com.shfl.model.UserInfo;
import com.shfl.stock.Stock;

public class UserInfoService {

	
	public ResultBean<ResultType> saveUserInfo(File file){
		Stock.USER_INFO = new HashMap<String, UserInfo>(); 
		List<String[]> list = new ArrayList<String[]>();
		StringBuilder sb =new StringBuilder();
		int i = 0;
		try {
			list = POIUtil.readExcel(file);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (!Objects.isNull(list)) {
			UserInfo userInfo = null;
			for (String[] str : list) {
				if (str.length < 7) {
					// TODO 判断员工信息的 文件
					return new ResultBean<ResultType>(new ResultType("9999","请选择规范的人员信息"));
				}
				if (!Stock.USER_INFO.containsKey(str[1]) && str.length >= 7) {
					if(str[7].equals("郭慧玲")){
						Stock.FALG = true;
					}
					Stock.JOB_SET.add(str[7]);
					userInfo = new UserInfo();
					userInfo.setUserNo(str[0]);
					userInfo.setUsername(str[1]);
					userInfo.setInTimem(str[3]);
					userInfo.setPrimarySector(str[5]);
					userInfo.setSecondarySector(str[6]);
					userInfo.setJobDescription(str[7]);
					if (null != str[1] && !str[1].isEmpty()) {
						Stock.USER_INFO.put(str[1], userInfo);
					}
					i++;
				} else {
					// TODO 员工重名
					sb.append(Stock.USER_INFO.containsKey(str[1]));
				}
			}
		}
		if(sb.toString().isEmpty()){
			return new ResultBean<ResultType>(new ResultType("0000","本次导入"+i+ "条人员信息"));
		}
		return new ResultBean<ResultType>(new ResultType("0000",i+ "本次导入"+i+ "条人员信息其中这些人员存在重复"+sb.toString()));
	}
}
